import { _decorator, Component, Node, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('HitIndicator')
export class HitIndicator extends Component {
    @property(Node)
    hitLine: Node;

    @property(Node)
    ballLine: Node;

    @property(Node)
    whiteLine: Node;

    onLoad() {
        this.hideAll();
    }

    hideAll(){
        this.hitLine.active = false;
        this.ballLine.active = false;
        this.whiteLine.active = false;
    }

    setHitLine(rotY: number, start: Vec3, len: number) {
        this.setLine(this.hitLine,rotY,start,len);
    }

    setBallLine(rotY: number, start: Vec3, len: number) {
        this.setLine(this.ballLine,rotY,start,len);
    }

    setWhiteLine(rotY: number, start: Vec3, len: number) {
        this.setLine(this.whiteLine,rotY,start,len);
    }

    private setLine(node:Node, rotY: number, start: Vec3, len: number){
        node.active = true;
        node.setRotationFromEuler(0, rotY, 0);
        node.setPosition(start);
        let c = node.children[0];
        c.setScale(len, 1, 1);
        c.setPosition(len / 2 - 0.5, 0, 0);
    }

    update(deltaTime: number) {

    }
}


